module.exports = () => {
	// 返回中间件函数
	return async function auth(app, next) {
		let {
			$dx
		} = app;
		// 校验 token		
		if ($dx.auth.errCode !== 0) {
			// 校验失败，抛出错误信息
			$dx.error($dx.auth.errMsg,null,4001);
		}
		if ($dx.auth.token) {
			$dx.request.token($dx.auth.token);
		}
		if ($dx.auth.tokenExpired) {
			$dx.request.tokenExpired($dx.auth.tokenExpired);
		}
		// 执行后续中间件
		await next()
	}
}
